<?php
	// News Summary
	if (DISPLAY_NEWS_SUMMARY == 'true') {
		require(DIR_WS_LANGUAGES . $_SESSION['language'] . '/' . FILENAME_NEWS_INDEX . '.php');

		require_once(DIR_WS_CLASSES . 'news.php');

		require_once(DIR_WS_FUNCTIONS . 'news.php');

		$date_selector = $db->Execute("select news_date_published from " . TABLE_NEWS_ARTICLES . " where news_status = '1' and to_days(news_date_published) >= to_days(now())-" . (int)DISPLAY_NEWS_SUMMARY_DAYS . " and to_days(news_date_published) <= to_days(now()) order by news_date_published desc limit 1");
		if ($date_selector->RecordCount() > 0) {

			$article = $db->Execute("select n.article_id, nt.news_article_name, nt.news_article_text, nt.news_article_shorttext, n.news_image, nt.news_image_text, n.news_date_published from " . TABLE_NEWS_ARTICLES . " n left join " . TABLE_NEWS_ARTICLES_TEXT . " nt on n.article_id = nt.article_id and nt.language_id = '" . (int)$_SESSION['languages_id'] . "' where n.news_status = '1' and n.news_date_published = '" . $date_selector->fields['news_date_published'] . "' order by n.sort_order limit 1");

// modified by zen-cart.cn
//			$newsDate = strtoupper(zen_date_long($date_selector->fields['news_date_published']));
			$newsDate = zen_date_long($date_selector->fields['news_date_published']);

			$newsHeaderLinks[] = array(
				'link' => zen_href_link(FILENAME_NEWS_RSS, '', 'NONSSL', false),
				'text' => TEXT_NEWS_RSS_FEED,
			);

			if ((zen_not_null($article->fields['news_image'])) && file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . $article->fields['news_image'])) {
				$articleImage = zen_image(DIR_WS_IMAGES . $article->fields['news_image'], $article->fields['news_image_text'], '', '', ' align="right" class="articleImage"');
			}

			$articleLink = zen_href_link(FILENAME_NEWS_ARTICLE, 'article_id=' . $article->fields['article_id']);
			$articleName = stripslashes($article->fields['news_article_name']);
			$articleSummary = news_create_news_summary($article->fields['news_article_text'], $article->fields['news_article_shorttext']);

			$news_subfooter = $db->Execute("select n.article_id, nt.news_article_name, n.news_date_published, n.news_status from " . TABLE_NEWS_ARTICLES . " n left join " . TABLE_NEWS_ARTICLES_TEXT . " nt on n.article_id = nt.article_id and nt.language_id = '" . (int)$_SESSION['languages_id'] . "' where n.news_status = '1' and n.news_date_published = '" . $date_selector->fields['news_date_published'] . "' and n.article_id != '" . $article->fields['article_id'] . "' order by n.sort_order");
			if ($news_subfooter->RecordCount() > 0) {
				$news_subfooter_array = array();
				while (!$news_subfooter->EOF) {
					$news_subfooter_array[] = array(
						'link' => zen_href_link(FILENAME_NEWS_ARTICLE, 'article_id=' . $news_subfooter->fields['article_id']),
						'text' => stripslashes($news_subfooter->fields['news_article_name']),
					);
	
					$news_subfooter->MoveNext();
				}

				$newsSubFooter = $news_subfooter_array;
				$newsSubFooterDate = zen_date_long($date_selector->fields['news_date_published']);
				$newsSubFooterDateURL = zen_href_link(FILENAME_NEWS_INDEX, 'date=' . substr($date_selector->fields['news_date_published'], 0, 10));
			}

			// Now display the news summary
			// Start the news display class
			$newsDisplay = new newsDisplay();

			// News article summary
			$newsDisplay->articleSummary($articleName, $articleSummary, $articleLink, $articleImage);

			// Display this news page
			// New page content is output in valid XHTML
			// You can change how it displays in the stylesheet_news.css file
			$newsDisplay->displayNewsPage();
		}
	}
?>